/**
 * @version 1.0.0
 * @author fxg1997
*/
<template>
  <div class="pages_content table">
    <el-container>
      <el-header>
        <breaDcrumb />
      </el-header>
      <el-main style="display: flex">
        <div>
          <div class="header_right" @click="showCardNav = !showCardNav">
            <div class="title">搜索</div>
            <div>
              <transition name="from"></transition>
              <span v-show="!showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-down"></i>
              </span>
              <transition name="to"></transition>
              <span v-show="showCardNav">
                <i style="margin-right: 5px" class="el-icon-arrow-up"></i>
              </span>
            </div>
          </div>
          <div v-show="showCardNav" class="hr"></div>
          <el-collapse-transition>
            <div v-show="showCardNav">
              <div class="search">
                <span style="display: inline-block;margin-bottom: 10px;">
                  <span style="margin-right: 12px">取用工程</span>
                  <el-input v-model="tableParam.engineeringName" style="width: 240px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">出库单号</span>
                  <el-input v-model="tableParam.stockOutNumber" style="width: 240px" clearable placeholder="请输入" @keyup.enter.native="gettableData()" />
                </span>
                <span style="margin-left: 24px">
                  <span style="margin-right: 12px">状态</span>
                  <el-select v-model="tableParam.materialsStatus" style="width:140px" placeholder="请选择">
                    <el-option label="全部" value="null"></el-option>
                    <el-option label="已签收" :value="2"></el-option>
                    <el-option label="回收中" :value="3"></el-option>
                  </el-select>
                </span>
                <el-button icon="el-icon-search" size="medium" class="bottom_all" @click="(tableParam.page = 1), gettableData()">查 询</el-button>
                <el-button size="medium" class="bottom_all_two" style="margin-left: 12px" @click="init()">重 置</el-button>
              </div>
            </div>
          </el-collapse-transition>
          <div class="hr"></div>
          <div class="card">
            <div class="card_nav">
              <div>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='ZHOUCAIHUISHOU'))!==-1" size="small" class="bottom_all_two" style="margin-left: 0" @click="open('dialog1')">
                  周材回收
                </el-button>
                <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='ZHOUCAIZUANYI'))!==-1" size="small" class="bottom_all_two" @click="open('dialog2')">
                  周材转移
                </el-button>
              </div>
              <div>
                <el-dropdown :hide-on-click="false" trigger="click" style="margin: 0 20px">
                  <el-link :underline="false">
                    <span class="el-icon--left">
                      <i class="iconfont iconicon_button_filtrate"></i>
                    </span>
                    筛选
                  </el-link>
                  <el-dropdown-menu slot="dropdown">
                    <el-dropdown-item v-for="(item, index) in table" :key="index">
                      <el-checkbox v-model="item.status">{{
                        item.label
                        }}</el-checkbox>
                    </el-dropdown-item>
                  </el-dropdown-menu>
                </el-dropdown>
              </div>
            </div>
            <div v-loading="tableLoading" class="card_info" :style="style">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" :data="tableData" tooltip-effect="dark">
                <template v-for="(item, index2) in table">
                  <el-table-column v-if="item.status" :key="index2" :label="item.label" align="center" :min-width="item.width" :fixed="item.label =='操作'||item.label =='工地负责人'||item.label =='运输安排'?'right':false">
                    <template slot-scope="scope">
                      <span v-if="item.label == '状态'">
                        <span v-if="scope.row.materialsStatus == 1" style="color: #969799">待签收</span>
                        <span v-if="scope.row.materialsStatus == 2" style="color: #00a754">已签收</span>
                        <span v-if="scope.row.materialsStatus == 3" style="color: #969799">回收中</span>
                        <span v-if="scope.row.materialsStatus == 4" style="color: #00a754">回收完成</span>
                      </span>
                      <div v-else-if="item.label == '取用工程'">
                        <span v-if="scope.row.takeStatus==1">自用回收</span>
                        <span v-else>{{scope.row.engineeringName}}</span>
                      </div>
                      <div v-else-if="item.label == '工地负责人'">
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='CHAKAN'))!==-1" class="bottom_one" size="mini" @click="open1('dialog4',scope.row.storagePeoples)">
                          查看
                        </el-button>
                      </div>
                      <div v-else-if="item.label == '运输安排'">
                        <el-button v-if="ButtonList.findIndex(res=>(res.buttonValue=='CHAKAN'))!==-1" class="bottom_one" size="mini" @click="open1('dialog5',scope.row.storageCars)">
                          查看
                        </el-button>
                      </div>
                      <div v-else-if="item.label == '操作'">
                        <el-button class="bottom_one" size="mini" @click="open1('dialog6',scope.row)">
                          收转明细
                        </el-button>
                      </div>
                      <span v-else>{{ scope.row[item.prop] }}</span>
                    </template>
                  </el-table-column>
                </template>
              </el-table>
            </div>
            <!-- <div class="card_bottom">
              <div class="card_bottom_left">
                <div class="top_page_totle">总共{{ total }}条</div>
                <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
              </div>
              <div>
                <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
              </div>
            </div> -->
          </div>
        </div>
      </el-main>
      <div class="card_bottom">
        <div class="card_bottom_left">
          <div class="top_page_totle">总共{{ total }}条</div>
          <el-pagination :current-page.sync="tableParam.page" :page-size="tableParam.pageSize" layout="prev, pager, next, jumper" :total="total" @current-change="gettableData()"></el-pagination>
        </div>
        <div>
          <el-button size="mini" icon="el-icon-refresh-right" class="bottom_all_two" @click="gettableData">刷新</el-button>
        </div>
      </div>
    </el-container>
    <!-- 周材回收 -->
    <el-dialog v-dialogDrag :visible.sync="dialog1" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">周材回收</span>
      <div>
        <div class="dialogTitle">工程单号</div>
        <el-form ref="reffromDate" :rules="rules" :inline="true" :model="recycle" label-width="110px">
          <el-form-item prop="takeStatus">
            <span slot="label">回收类型</span>
            <el-radio-group v-model="recycle.takeStatus" @change="change()">
              <el-radio :label="1">自用回收</el-radio>
              <el-radio :label="2">工程回收</el-radio>
            </el-radio-group>
          </el-form-item>
          <div style="display:flex;">
            <el-form-item v-if="recycle.takeStatus==2" prop="engineeringId">
              <span slot="label">回收工程</span>
              <el-select v-model="recycle.engineeringId" style="width:280px" placeholder="请选择" @change="change()">
                <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.engineeringName" :value="item.engineeringId"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="outStorageId">
              <span slot="label">出库单号</span>
              <el-select :key="101" v-model="recycle.outStorageId" style="width:280px" placeholder="请选择" @change="change2()">
                <el-option v-for="(item0, index0) in stockOutNumberList" :key="index0" :label="item0.stockOutNumber" :value="item0.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div class="dialogTitle">回收明细</div>
          <div style="padding-bottom:20px">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="recycleDetails">
              <el-table-column label="名称" align="center" prop="name">
              </el-table-column>
              <el-table-column label="规格" align="center" prop="specificationName">
              </el-table-column>
              <el-table-column label="类型" align="center" prop="type">
              </el-table-column>
              <el-table-column label="出库数量" align="center" prop="signAmount">
              </el-table-column>
              <el-table-column label="待回收" align="center">
                <template slot-scope="scope">
                  {{scope.row.signAmount-scope.row.recycleAccount-scope.row.transferAccount-scope.row.scrapAccount-scope.row.recycleSureAccount-scope.row.scrapSureAccount}}
                </template>
              </el-table-column>
              <el-table-column label="本次回收数量" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.recycleAccount1" style="width:100%" placeholder="请输入" onkeypress='return( /\d|\./.test(String.fromCharCode(event.keyCode)))' @input="fromDate.tubularColumn=$regExp.checkNum(fromDate.tubularColumn)" @blur="fromDate.tubularColumn=$regExp.blurCheckNum(fromDate.tubularColumn),sizeNumber(scope.row,'recycleAccount1')">
                  </el-input>
                </template>
              </el-table-column>
              <el-table-column label="本次报废数量" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.scrapAccount1" style="width:100%" placeholder="请输入" onkeypress='return( /\d|\./.test(String.fromCharCode(event.keyCode)))' @input="fromDate.tubularColumn=$regExp.checkNum(fromDate.tubularColumn)" @blur="fromDate.tubularColumn=$regExp.blurCheckNum(fromDate.tubularColumn),sizeNumber(scope.row,'scrapAccount1')">
                  </el-input>
                </template>
              </el-table-column>
            </el-table>
            <div v-if="recycle.takeStatus==2">
              <div class="dialogTitle" style="padding-top:20px">人员车辆</div>
              <div style="padding-bottom:10px">
                <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="additem2()">
                  <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                  添加
                </el-button>
              </div>
              <div style="padding-bottom:20px">
                <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="storageCars">
                  <el-table-column label="运输负责人" align="center">
                    <template slot-scope="scope">
                      <el-select ref="driverId" v-model="scope.row.driverId " style="widrh:100%;max-width:200px" placeholder="请选择" @change="$nextTick(()=>{scope.row.driver = $refs.driverId.selectedLabel})">
                        <el-option v-for="(item, index) in driverList" :key="index" :label="item.name" :value="item.id"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="运输车辆" align="center">
                    <template slot-scope="scope">
                      <el-select v-model="scope.row.plateNumber " style="widrh:100%;max-width:200px" placeholder="请选择">
                        <el-option v-for="(item, index) in plateNumberList" :key="index" :value="item.plateNumber"></el-option>
                      </el-select>
                    </template>
                  </el-table-column>
                  <el-table-column label="操作" align="left">
                    <template slot-scope="scope">
                      <el-button size="mini" class="bottom_two" @click="delItem2(scope.$index)">
                        <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                        删除
                      </el-button>
                    </template>
                  </el-table-column>
                </el-table>
              </div>
              <!-- <div>
                <el-form-item prop="destination">
                  <span slot="label">回收目的地</span>
                  <el-input v-model="recycle.destination" style="width:280px" placeholder="请输入"></el-input>
                </el-form-item>
              </div>
              <el-form-item prop="remark">
                <span slot="label">备注</span>
                <el-input v-model="recycle.remark" style="width:750px" placeholder="请填写备注" class="textarea" type="textarea" resize="none" rows="5"></el-input>
              </el-form-item> -->
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog1')">取 消</el-button>
        <el-button v-if="recycle.takeStatus == 1" class="bottom_all" style="margin-left: 24px" @click="submit1()">确 定</el-button>
        <el-button v-else class="bottom_all" style="margin-left: 24px" @click="submit1()">确定并通知工地负责人</el-button>
      </span>
    </el-dialog>
    <!-- 周材转移 -->
    <el-dialog v-dialogDrag :visible.sync="dialog2" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">周材转移</span>
      <div>
        <div class="dialogTitle">转出工程</div>
        <el-form ref="reffromDate1" :rules="rules1" :inline="true" :model="mOutStorage" label-width="110px">
          <div style="display:flex;">
            <el-form-item prop="engineeringIdSource">
              <span slot="label">工程名称</span>
              <el-select v-model="mOutStorage.engineeringIdSource" style="width:280px" placeholder="请选择" @change="change3()">
                <el-option v-for="(item, index) in engineeringList" :key="index" :label="item.engineeringName" :value="item.engineeringId"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item prop="outStorageId">
              <span slot="label">出库单号</span>
              <el-select ref="outStorageId" v-model="mOutStorage.outStorageId" style="width:280px" placeholder="请选择" @change="change4()">
                <el-option v-for="(item, index) in stockOutNumberList" :key="index" :label="item.stockOutNumber" :value="item.id"></el-option>
              </el-select>
            </el-form-item>-
          </div>
          <div style="display:flex;">
            <el-form-item>
              <span slot="label">工程地址</span>
              <div style="width:280px">{{mOutStorage.place}}</div>
            </el-form-item>
            <el-form-item>
              <span slot="label">工地负责人</span>
              <div style="width:280px">{{mOutStorage.principal1}}</div>
            </el-form-item>
          </div>
          <el-form-item>
            <span slot="label">联系电话</span>
            <div style="width:280px">{{mOutStorage.phone1}}</div>
          </el-form-item>
          <div class="dialogTitle">转入工程</div>
          <div style="display:flex;">
            <el-form-item prop="engineeringId">
              <span slot="label">转移工程</span>
              <el-select v-model="mOutStorage.engineeringId" style="width:280px" placeholder="请选择" @change="change5()">
                <el-option v-for="(item, index) in engineeringList1" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
          </div>
          <div style="display:flex;">
            <el-form-item>
              <span slot="label">工程地址</span>
              <div style="width:280px"> {{mOutStorage.sourcePlace}}</div>
            </el-form-item>
            <el-form-item>
              <span slot="label">出库日期</span>
              {{new Date().Format('yyyy-MM-dd hh:mm:ss')}}
            </el-form-item>
          </div>
          <div style="display:flex;">
            <el-form-item prop="principal2">
              <span slot="label">工地负责人</span>
              <el-select v-model="mOutStorage.principal2" multiple style="width:280px" placeholder="请选择" @change="change6()">
                <el-option v-for="(item, index) in userList" :key="index" :label="item.name" :value="item.id"></el-option>
              </el-select>
            </el-form-item>
            <el-form-item>
              <span slot="label">联系电话</span>
              <div>{{mOutStorage.phone}}</div>
            </el-form-item>
          </div>
          <el-form-item>
            <span slot="label">备注</span>
            <el-input v-model="mOutStorage.remark" style="width:750px" placeholder="请填写备注" class="textarea" type="textarea" resize="none" rows="5"></el-input>
          </el-form-item>
          <div class="dialogTitle">回收明细</div>
          <div style="padding-bottom:20px">
            <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="recycleDetails">
              <el-table-column label="名称" align="center" prop="name">
              </el-table-column>
              <el-table-column label="规格" align="center" prop="specificationName">
              </el-table-column>
              <el-table-column label="类型" align="center" prop="type">
              </el-table-column>
              <el-table-column label="出库数量" align="center" prop="signAmount">
              </el-table-column>
              <el-table-column label="可转移量" align="center">
                <template slot-scope="scope">
                  {{scope.row.num=scope.row.signAmount-scope.row.recycleAccount-scope.row.transferAccount-scope.row.scrapAccount-scope.row.recycleSureAccount-scope.row.scrapSureAccount}}
                </template>
              </el-table-column>
              <el-table-column label="转移量" align="center">
                <template slot-scope="scope">
                  <el-input v-model="scope.row.stockOutAmount1" style="width:100%" placeholder="请输入" clearable onkeypress='return( /\d/.test(String.fromCharCode(event.keyCode)))' onblur="setTimeout(()=>{if(value < 1 ){ value = 1}},100)" @change="inputstockOutAmount1(scope.row)" @input="scope.row.stockOutAmount1=$regExp.checkNum(scope.row.stockOutAmount1)" @blur="scope.row.stockOutAmount1=$regExp.blurCheckNum(scope.row.stockOutAmount1)">
                  </el-input>
                </template>
              </el-table-column>
            </el-table>
            <div class="dialogTitle" style="padding-top:20px">人员车辆</div>
            <div style="padding-bottom:10px">
              <el-button size="mini" class="bottom_all" style="margin-left: 0" @click="additem2()">
                <i class="icon iconfont iconicon_button_add" style="font-size: 12px"></i>
                添加
              </el-button>
            </div>
            <div style="padding-bottom:20px">
              <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="storageCars">
                <el-table-column label="运输负责人" align="center">
                  <template slot-scope="scope">
                    <el-select ref="driverId" v-model="scope.row.driverId " style="widrh:100%;max-width:200px" placeholder="请选择" @change="$nextTick(()=>{scope.row.driver = $refs.driverId.selectedLabel})">
                      <el-option v-for="(item, index) in driverList" :key="index" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="运输车辆" align="center">
                  <template slot-scope="scope">
                    <el-select v-model="scope.row.plateNumber " style="widrh:100%;max-width:200px" placeholder="请选择">
                      <el-option v-for="(item, index) in plateNumberList" :key="index" :value="item.plateNumber"></el-option>
                    </el-select>
                  </template>
                </el-table-column>
                <el-table-column label="操作" align="left">
                  <template slot-scope="scope">
                    <el-button size="mini" class="bottom_two" @click="delItem2(scope.$index)">
                      <i class="icon iconfont iconicon_button_delete" style="font-size: 12px"></i>
                      删除
                    </el-button>
                  </template>
                </el-table-column>
              </el-table>
            </div>
          </div>
        </el-form>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog2')">取 消</el-button>
        <el-button class="bottom_all" style="margin-left: 24px" @click="submit2()">确 定</el-button>
      </span>
    </el-dialog>
    <!-- 工地负责人 -->
    <el-dialog v-dialogDrag :visible.sync="dialog4" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">工地负责人</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="工地负责人" align="center" prop="principal"></el-table-column>
          <el-table-column label="联系电话" align="center" prop="phone"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog4')">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 运输安排 -->
    <el-dialog v-dialogDrag :visible.sync="dialog5" width="680px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">运输安排</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="运输负责人" align="center" prop="driver"></el-table-column>
          <el-table-column label="运输车辆" align="center" prop="plateNumber"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog5')">取 消</el-button>
      </span>
    </el-dialog>
    <!-- 查看收转明细 -->
    <el-dialog v-dialogDrag :visible.sync="dialog6" width="980px" :close-on-click-modal="false">
      <span slot="title" class="dialog-title">取用信息</span>
      <div class="dialoginfo">
        <div class="form-title" style="margin-bottom:10px;">订单号：{{infoData.orderNo}}</div>
        <el-form :inline="true" :model="infoData" label-width="100px">
          <el-form-item>
            <span slot="label">取用工程：</span>
            <div style="width: 320px;">{{infoData.engineeringName}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">工程地址：</span>
            <div style="width: 320px;">{{infoData.place}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">工地负责人：</span>
            <div style="width: 320px;">{{infoData.principal}}</div>
          </el-form-item>
          <el-form-item>
            <span slot="label">联系电话：</span>
            <div style="width: 320px;">{{infoData.phone}}</div>
          </el-form-item>
          <el-form-item prop="person">
            <span slot="label">出库日期：</span>
            <div style="width: 320px;">{{infoData.createTime}}</div>
          </el-form-item>
          <el-form-item prop="person">
            <span slot="label">出库备注：</span>
            <div style="width: 320px;">{{infoData.remark}}</div>
          </el-form-item>
        </el-form>
      </div>
      <span slot="title" class="dialog-title">查看周材详情</span>
      <div>
        <el-table :header-cell-style="{ background: '#f3f6f9' }" :cell-style="{ borderRight: 'none' }" border stripe style="width: 100%" tooltip-effect="dark" :data="lowData">
          <el-table-column label="名称" align="center" prop="name"></el-table-column>
          <el-table-column label="规格" align="center" prop="specificationName"></el-table-column>
          <el-table-column label="类型" align="center" prop="type"></el-table-column>
          <el-table-column label="出库数量" align="center" prop="signAmount"></el-table-column>
          <el-table-column label="待回收" align="center">
            <template slot-scope="scope">
              {{ToBeRecycledFun(scope.row)}}
            </template>
          </el-table-column>
          <el-table-column label="已回收" align="center" prop="recycleAccount"></el-table-column>
          <el-table-column label="已转移" align="center" prop="transferAccount"></el-table-column>
          <el-table-column label="已报废" align="center" prop="scrapAccount"></el-table-column>
        </el-table>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button class="bottom_all_two" @click="reset('dialog6')">取 消</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import mixin from "@/mixins/ICPSmixin.js";

import { queryList as queryListAs } from "@/api/besSer/WMmanagement/outbound.js";
import {
  queryPage, queryList, saveRcycleResord, transferMaterials, queryStockOutNumber
} from "@/api/besSer/WMmanagement/recycling.js";
import {
  particularsList, get_simple_user_listBycompanyId, queryListCar, queryListMaterials
} from "@/api/besSer/WMmanagement/outbound.js";
import { getUserInfo } from "@/utils/auth"
let materialsStatus
let low_id
let storagePeoples
export default {
  mixins: [mixin],
  data() {
    return {
      /*表格增删改查及下载接口*/
      queryPage: queryPage,
      /*表格数据*/
      table: [
        // { label: "序号", width: "auto", prop: "", status: true },
        { label: "取用工程", width: "120", prop: "engineeringName", status: true },
        { label: "出库单号", width: "120", prop: "stockOutNumber", status: true },
        { label: "出库数量", width: "120", prop: "takeAmount", status: true },
        { label: "出库日期", width: "160", prop: "createTime", status: true },
        { label: "待回收数量", width: "120", prop: "waitRecycleAccount", status: true },
        { label: "已回收数量", width: "120", prop: "recycleAccount", status: true },
        { label: "已报废数量", width: "120", prop: "scrapAccount", status: true },
        { label: "转移数量", width: "120", prop: "transferAccount", status: true },
        { label: "出库备注", width: "120", prop: "remark", status: true },
        { label: "状态", width: "120", prop: "", status: true },
        { label: "操作", width: "120", prop: "", status: true }
      ],
      pagesType: 0,
      /*添加表单数据*/
      rules: {
        engineeringId: [{ required: true, message: "请选择回收工程", trigger: "change" }],
        outStorageId: [{ required: true, message: "请选择出库单号", trigger: "change" }],
        destination: [{ required: true, message: "请输入回收目的地", trigger: "blur" }]
      },
      rules1: {
        engineeringId: [{ required: true, message: "请选择转移工程", trigger: "change" }],
        outStorageId: [{ required: true, message: "请选择出库单号", trigger: "change" }],
        engineeringIdSource: [{ required: true, message: "请输入转出工程", trigger: "change" }],
        principal2: [{ required: true, message: "请选择工地负责人", trigger: "change" }],
      },
      recycle: {
        takeStatus: 1,
        engineeringId: '',
        stockOutNumber: '',
        destination: '',
        outStorageId: '',
        remark: ''
      },
      recycleDetails: [],
      storageCars: [],
      dialog1: false,
      dialog2: false,
      dialog4: false,
      dialog5: false,
      dialog6: false,
      lowData: [],
      engineeringList: [],
      stockOutNumberList: [],
      engineeringList1: [],
      plateNumberList: [],
      driverList: [],
      userList: [],
      mOutStorage: {
        engineeringName: '',
        engineeringId: '',
        outStorageId: '',
        place: '',
        takeAmount: '',
        remark: '',
        principal1: '',
        phone1: '',
        principal2: [],
        phone: '',
        principal: [],
        engineeringNameSource: '',
        engineeringIdSource: '',
        sourcePlace: '',
      },
      infoData: {}
    };
  },
  created() {
    /*存储拷贝的原初始化fromDate数据*/
    this.tableParam = { ...this.tableParam, materialsStatus: "", engineeringName: "", stockOutNumber: '', status: 1 };
    this.gettableData();
  },
  methods: {
    /**周材回收*/
    change() {
      this.stockOutNumberList = []
      this.recycle.outStorageId = ''
      let a = this.engineeringList.find(res => (res.engineeringId == this.recycle.engineeringId))
      if (this.recycle.takeStatus == 1) {
        queryStockOutNumber({ takeStatus: 1 }).then((res) => {
          this.stockOutNumberList = res.data
        })
      } else {
        if (a) {
          this.recycle.engineeringName = a.engineeringName
          this.stockOutNumberList = a.stockOutNumberList
        }
      }
      this.recycle.stockOutNumber = ''
      this.recycleDetails = []
      this.storageCars = []
    },
    async change2() {
      const { data } = await particularsList({ outStorageId: this.recycle.outStorageId })
      let a = this.stockOutNumberList.find(res => (res.id == this.recycle.outStorageId))
      materialsStatus = a.takeStatus
      this.recycle.stockOutNumber = a.stockOutNumber
      this.recycleDetails = data
    },
    additem2() {
      this.storageCars.push({
        driver: '',
        driverId: '',
        plateNumber: ''
      })
    },
    delItem2(index) {
      this.storageCars.splice(index, 1)
    },
    submit1() {
      let _this = this;
      _this.$refs.reffromDate.validate((valid) => {
        if (valid) {
          let recycleDetails = _this.recycleDetails.map(res => {
            return {
              name: res.name,
              specificationName: res.specificationName,
              specificationId: res.specificationId,
              type: res.type,
              typeId: res.typeId,
              stockOutAmount: res.signAmount,//写错了就用这个字段
              recycleAccount: res.recycleAccount1,
              scrapAccount: res.scrapAccount1,
              storageParticularsId: res.id
            }
          })
          let obj = {
            materialsStatus: materialsStatus,
            recycleDetails: recycleDetails,
            storageCars: _this.storageCars,
            recycle: _this.recycle,
          }
          if (this.recycle.takeStatus == 1) {
            obj.outStorageId = this.recycle.outStorageId
          }
          obj.takeStatus = this.recycle.takeStatus
          saveRcycleResord(obj).then(res => {
            if (res.code === 1001) {
              _this.reset('dialog1')
              _this.gettableData();
              _this.$message({
                message: '保存成功',
                type: "success",
              });
            }
          })
        } else {
          return false;
        }
      });

    },
    /**周材转移*/
    change3() {
      this.mOutStorage.outStorageId = ''
      let a = this.engineeringList.find(res => (res.engineeringId == this.mOutStorage.engineeringIdSource))
      this.mOutStorage.engineeringNameSource = a.engineeringName
      this.stockOutNumberList = a.stockOutNumberList
      this.mOutStorage.takeAmount = ''
      this.mOutStorage.principal1 = ''
      this.mOutStorage.phone1 = ''
      this.mOutStorage.place = ''
      this.recycleDetails = []
      this.storageCars = []
    },
    async change4() {
      const { data } = await particularsList({ outStorageId: this.mOutStorage.outStorageId })
      let a = this.stockOutNumberList.find(res => (res.id == this.mOutStorage.outStorageId))
      materialsStatus = a.takeStatus
      low_id = a.id
      this.mOutStorage.takeAmount = a.takeAmount
      this.mOutStorage.principal1 = a.principal
      this.mOutStorage.phone1 = a.phone
      this.mOutStorage.place = a.place
      this.recycleDetails = data
    },
    async change5() {
      this.mOutStorage.principal2 = []
      const { data } = await queryListAs({ engineeringId: this.mOutStorage.engineeringId })
      this.userList = data.map((res) => {
        return { name: res.principal, id: res.principalId, phone: res.phone }
      })
      let a = this.engineeringList1.find(res => (res.id == this.mOutStorage.engineeringId))
      // this.mOutStorage.engineeringNameSource = a.name
      this.mOutStorage.engineeringName = a.name
      this.mOutStorage.sourcePlace = a.place
    },
    async change6() {
      storagePeoples = this.userList.filter((item) => (
        this.mOutStorage.principal2.some((items) => (item.id == items))
      ))
      console.log(storagePeoples)
      this.mOutStorage.phone = storagePeoples.map(res => (res.phone)).join(',')
      this.mOutStorage.principal = storagePeoples.map(res => (res.name)).join(',')
    },
    submit2() {
      let _this = this;
      _this.$refs.reffromDate1.validate((valid) => {
        if (valid) {
          if (_this.storageCars.length == 0 || !_this.storageCars[0].driverId) {
            _this.$message({
              message: '请选择运输负责人',
              type: 'warning'
            });
            return
          }
          let recycleDetails = _this.recycleDetails.map(res => {
            return {
              name: res.name,
              specificationName: res.specificationName,
              specificationId: res.specificationId,
              type: res.type,
              typeId: res.typeId,
              stockOutAmount: res.stockOutAmount1,
              repertoryManageId: res.repertoryManageId,
              id: res.id
            }
          })
          let Peoples = storagePeoples.map(res => {
            return {
              principal: res.name,
              principalId: res.id,
              phone: res.phone,
            }
          })
          let obj = {
            id: low_id,
            mOutStorage: _this.mOutStorage,
            materialsStatus: materialsStatus,
            particulars: recycleDetails,
            storageCars: _this.storageCars,
            storagePeoples: Peoples
          }
          transferMaterials(obj).then(res => {
            if (res.code == 1001) {
              _this.reset('dialog2')
              _this.gettableData();
              _this.$message({
                message: '保存成功',
                type: "success",
              });
            }
          })
        } else {
          return false;
        }
      });
    },
    async open(key) {
      this.userList = []
      this.recycleDetails = []
      this.storageCars = []
      this.stockOutNumberList = []
      const { data } = await queryList()
      const { data: driver } = await get_simple_user_listBycompanyId({ orgznizationId: getUserInfo().companyId, roleId: '12719832957063168' })//周材司机
      this.driverList = driver
      const { data: plateNumber } = await queryListCar({ companyId: getUserInfo().companyId, carTypeId: '0c51dc71d20b4a1cb35645156d6a820d' })//车辆类型-东风车
      this.plateNumberList = plateNumber
      this.engineeringList = data
      if (key == 'dialog1') {
        this.recycle = this.$options.data().recycle
        this[key] = true
        setTimeout(() => {
          this.$refs.reffromDate.clearValidate();
        }, 10)
      }
      if (key == 'dialog2') {//周材转移
        // const { data: user } = await get_simple_user_listBycompanyId({ orgznizationId: getUserInfo().companyId, roleId: '5b1ca600fb4f4a7e898506bc803449f6' })//工地周材负责人
        // this.userList = user
        const { data: engineeringList1 } = await queryListMaterials({ companyId: getUserInfo().companyId })
        this.engineeringList1 = engineeringList1
        this.mOutStorage = this.$options.data().mOutStorage
        this[key] = true
        setTimeout(() => {
          this.$refs.reffromDate1.clearValidate();
        }, 10)
      } else {//周材回收
        this.change()
      }
    },
    reset(key) {
      this[key] = false
    },
    async open1(key, low) {
      if (key == "dialog6") {
        const { data } = await particularsList({ outStorageId: low.id })
        this.lowData = data
        this.infoData = low
      } else {
        this.lowData = low
      }
      this[key] = true
    },
    /*重置数据,此方法必须存在，并且方发只重置条件*/
    init() {
      this.tableParam.engineeringName = "";
      this.tableParam.materialsStatus = "";
      this.tableParam.stockOutNumber = "";
      this.gettableData();
    },
    ToBeRecycledFun(row) {
      let size = row.signAmount - row.recycleAccount - row.transferAccount - row.scrapAccount
      return size
    },
    sizeNumber(row, key) {
      console.log(JSON.parse(JSON.stringify(row)))
      let num = row.signAmount - row.recycleAccount - row.transferAccount - row.scrapAccount - row.recycleSureAccount - row.scrapSureAccount - row.remainingTransfer
      let num0 = Number(row.recycleAccount1) + Number(row.scrapAccount1)
      if (key == 'recycleAccount1') {
        if (num0 > num) {
          this.$message({
            message: '本次回收数量+本次报废数量的和不能超过' + num,
            type: 'warning'
          });
          row[key] = 0
        }
      } else {
        if (num0 > num) {
          this.$message({
            message: '本次回收数量+本次报废数量的和不能超过' + num,
            type: 'warning'
          });
          row[key] = 0
        }
      }
    },
    inputstockOutAmount1(row) {
      if (row.stockOutAmount1 > row.num) {
        this.$message({
          message: '转移量不能超过' + row.num,
          type: 'warning'
        });
        row.stockOutAmount1 = row.num
      }
    }
  },
};
</script>

<style lang="scss" scoped>
.dialogTitle {
  font-size: 18px;
  font-weight: bold;
  color: #000;
  padding: 0 0 20px;
}
.el-input,
.el-select {
  width: 240px;
}
/*
 <el-link class="table_link" :underline="false">查看配合比</el-link>*/
.table_link {
  margin: 0 10px;
  color: $bg_color;
  cursor: pointer;
}

.table_link:hover {
  opacity: 0.8;
}
</style>
